package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerPrincipal;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;

import javax.swing.ImageIcon;

public class TelaCadastroMedico extends JFrame {

	private JPanel contentPane;
	static JTextField txt_nome;
	static JTextField txt_telefone;
	static JTextField txt_email;
	static JTextField txt_crm;
	static Integer codAletrar;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaCadastroMedico frame = new TelaCadastroMedico();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaCadastroMedico() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 650, 400);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel label = new JLabel("Nome:");
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		label.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		label.setBounds(45, 98, 46, 14);
		contentPane.add(label);

		txt_nome = new JTextField();
		txt_nome.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		txt_nome.setColumns(10);
		txt_nome.setBounds(101, 93, 318, 25);
		contentPane.add(txt_nome);

		txt_telefone = new JTextField();
		txt_telefone.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		txt_telefone.setColumns(10);
		txt_telefone.setBounds(101, 131, 159, 25);
		contentPane.add(txt_telefone);

		JLabel label_1 = new JLabel("Telefone:");
		label_1.setHorizontalAlignment(SwingConstants.RIGHT);
		label_1.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		label_1.setBounds(25, 136, 66, 14);
		contentPane.add(label_1);

		JLabel label_2 = new JLabel("Email:");
		label_2.setHorizontalAlignment(SwingConstants.RIGHT);
		label_2.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		label_2.setBounds(25, 172, 66, 14);
		contentPane.add(label_2);

		txt_email = new JTextField();
		txt_email.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		txt_email.setColumns(10);
		txt_email.setBounds(101, 167, 318, 25);
		contentPane.add(txt_email);

		JLabel label_3 = new JLabel("CRM:");
		label_3.setHorizontalAlignment(SwingConstants.RIGHT);
		label_3.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		label_3.setBounds(25, 208, 66, 14);
		contentPane.add(label_3);

		txt_crm = new JTextField();
		txt_crm.setFont(new Font("Times New Roman", Font.PLAIN, 16));
		txt_crm.setColumns(10);
		txt_crm.setBounds(101, 203, 159, 25);
		contentPane.add(txt_crm);

		JButton btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = txt_nome.getText();
				String telefone = txt_telefone.getText();
				String email = txt_email.getText();
				String crm = txt_crm.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				control.InserirMedico(nome, telefone, email, crm);
				TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
				telaMensagem.setLocationRelativeTo(null);
				telaMensagem.setVisible(true);
				txt_nome.setText("");
				txt_telefone.setText("");
				txt_email.setText("");
				txt_crm.setText("");

			}
		});
		btnSalvar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnSalvar.setBackground(Color.WHITE);
		btnSalvar.setBounds(377, 269, 100, 43);
		contentPane.add(btnSalvar);

		JButton btnSair = new JButton("Sair");
		btnSair.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnSair.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnSair.setBackground(Color.WHITE);
		btnSair.setBounds(487, 269, 100, 43);
		contentPane.add(btnSair);
		
		JLabel lblCadastrarMdico = new JLabel("M\u00E9dico");
		lblCadastrarMdico.setForeground(new Color(0, 0, 128));
		lblCadastrarMdico.setFont(new Font("Franklin Gothic Medium Cond", Font.PLAIN, 25));
		lblCadastrarMdico.setBounds(32, 28, 173, 30);
		contentPane.add(lblCadastrarMdico);
		
		JButton btnLocalizar = new JButton("Listar");
		btnLocalizar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TelaListarMedicos telaListaMedico = new TelaListarMedicos();
				telaListaMedico.setLocationRelativeTo(null);
				telaListaMedico.setVisible(true);
			}
		});
		btnLocalizar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnLocalizar.setBackground(Color.WHITE);
		btnLocalizar.setBounds(45, 269, 100, 43);
		contentPane.add(btnLocalizar);
		
		JButton btnDeletar = new JButton("Deletar");
		btnDeletar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = txt_nome.getText();
				String telefone = txt_telefone.getText();
				String email = txt_email.getText();
				String crm = txt_crm.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.deletarMedico(codAletrar, nome, telefone, email, crm);
					TelaMensagemDeletar telaMensagem = new TelaMensagemDeletar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_nome.setText("");
					txt_telefone.setText("");
					txt_email.setText("");
					txt_crm.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		btnDeletar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnDeletar.setBackground(Color.WHITE);
		btnDeletar.setBounds(267, 269, 100, 43);
		contentPane.add(btnDeletar);
		
		JButton btnEditar = new JButton("Alterar");
		btnEditar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = txt_nome.getText();
				String telefone = txt_telefone.getText();
				String email = txt_email.getText();
				String crm = txt_crm.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.editarMedico(codAletrar, nome, telefone, email, crm);
					TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_nome.setText("");
					txt_telefone.setText("");
					txt_email.setText("");
					txt_crm.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		btnEditar.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnEditar.setBackground(Color.WHITE);
		btnEditar.setBounds(155, 269, 100, 43);
		contentPane.add(btnEditar);
		
		JLabel label_4 = new JLabel("");
		label_4.setIcon(new ImageIcon("arquivos\\FundoCadastroMedico.png"));
		label_4.setBounds(0, 0, 644, 371);
		contentPane.add(label_4);
	}

}
